from django.db import models

# Create your models here.
class User(models.Model):
    sAMAccountName = models.CharField(verbose_name="用户名",max_length=64)
    mail = models.CharField(verbose_name="邮箱",max_length=64,blank=True,null=True)
    title = models.CharField(verbose_name="工作岗位",max_length=128,blank=True,null=True)
    telephoneNumber = models.CharField(verbose_name="联系方式",max_length=128,blank=True,null=True)
    displayName = models.CharField(verbose_name="显示名称",max_length=128,blank=True,null=True)
    roles = models.ManyToManyField(verbose_name="对应角色",to="Role")
    department = models.ForeignKey(verbose_name="部门",to="Department",blank=True,null=True)

    def __str__(self):
        return self.sAMAccountName

class Department(models.Model):
    name = models.CharField(verbose_name="所属部门",max_length=128,blank=True,null=True)

    def __str__(self):
        return self.name


class Role(models.Model):
    title = models.CharField(verbose_name="角色",max_length=64)
    permissions = models.ManyToManyField(verbose_name="对应权限",to="Permission")

    def __str__(self):
        return self.title


class Permission(models.Model):
    title = models.CharField(verbose_name="权限",max_length=64)
    url = models.CharField(verbose_name="url",max_length=128)

    action = models.CharField(verbose_name="对应操作",max_length=32)
    permissiongroup = models.ForeignKey(verbose_name="权限组",to="PermissionGroup")

    def __str__(self):
        return self.title


class PermissionGroup(models.Model):
    title = models.CharField(verbose_name="权限组",max_length=64)
    def __str__(self):
        return self.title